<template>
  <div>
    <div class="center">
      <el-row :gutter="20">
        <el-col :span="24"><div class="centerTitle">平台推荐组合</div></el-col>
      </el-row>
      <p>京师壹心平台推荐组合，由北京师范大学心理学专家团研发的组合量表，平台特色产品，定期更新组合量表，强烈推荐优先使用。</p>
      <el-row :gutter="20" class="platformTable">
        <simple-table :tableConfig="tableConfig" :tableData="tableData" @operation="getOperation"></simple-table>
      </el-row>
    </div>
  </div>
</template>
<script>
import simpleTable from '@/components/simpleTable.vue'
import {APISURVEYLIST, APIPRETESTPLAN} from '@/common/api.js'
export default {
  components: {
    simpleTable
  },
  data () {
    return {
      tableConfig: {
        load: false,
        size: 'small', // 表格大小
        style: 'width:100%', // 表格宽度
        align: 'center',
        border: true,
        config: [
          {id: 'tag', name: '特色组合类型'},
          {id: 'student_title', name: '名称'},
          {id: 'count', name: '测评量表数量'},
          {id: 'topics_num', name: '题量'},
          {id: 'operation', name: '操作', list: [{id: 'instructions', name: '指导说明'}]}
        ]
      },
      tableData: [],
      menuList: []
    }
  },
  created () {
    this.menuList = sessionStorage.getItem('list')
    if (this.menuList.includes('surveyDispatch')) {
      var operation1 = {id: 'test', name: '试测'}
      this.tableConfig.config.forEach(item => {
        if (item.id === 'operation') {
          item.list.push(operation1)
        }
      })
    }
    this.tableList()
  },
  methods: {
    tableList () {
      APISURVEYLIST({
        type: 2
      }).then((res) => {
        if (res.status === 1) {
          this.tableData = res.data.list
        } else {
          this.$message.error(res.msg)
          this.tableData = []
          this.tableData.push(this.seacherTab)
        }
      }).catch((err) => {
        this.$message.error(err.msg)
      })
    },
    getOperation (e) {
      if (e.id === 'instructions') {
        this.$alert(e.rows.summary, '指导说明', {
          confirmButtonText: '确定'
        })
      } else if (e.id === 'test') {
        this.testFn(e.rows)
      }
    },
    testFn (row) {
      APIPRETESTPLAN({
        plan_type: 1,
        public_ids: row.id
      }).then((res) => {
        if (res.status === 1) {
          window.open(res.data.url, '_blank')
        } else {
          this.$message.error(res.msg)
        }
      }).catch((err) => {
        this.$message.error(err.msg)
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.platformTable{
  margin-top: 2vh;
}
</style>
